<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>柒拾佳护</title>
		<link href="css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="css/icons-extra.css" />
		<link rel="stylesheet" href="css/iconfont.css" />
		<link rel="stylesheet" href="css/main.css" />
		<style>
			ul {
				font-size: 14px;
				color: #8f8f94;
			}
			
			.mui-btn {
				padding: 10px;
			}
			
			#kefu {
				font-size: 0.5rem;
				line-height: 30px;
			}
			
			header button img {
				width: 0.3rem;
			}
			
			.mui-bar {
				box-shadow: 0 0 1px rgba(185, 185, 185, 1);
			}
			
			html,
			body {
				height: 100%;
				margin: 0px;
				padding: 0px;
			}
			
			.mui-icon .mui-badge {
				padding: 5px 5px;
				margin-left: -5px;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav" style="padding-right: 15px;">
			<h1 id="title" class="mui-title">柒拾佳护</h1>
			<!--<button id="chooseCity" class="mui-btn  mui-btn-link mui-pull-right">
					<img src="images/exit/zuobiao.png" />
					<span id="city_name">长春</span>
			</button>-->
		</header>
		<input type="hidden" id="customer_id" />
		<nav class="mui-bar mui-bar-tab">
			<a id="defaultTab" class="mui-tab-item mui-active home" href="subpages/tab-webview-subpage-home.html">
				<span class="mui-icon iconfont icon-icon-test"></span>
				<span class="mui-tab-label">首页</span>
			</a>
			<a class="mui-tab-item zixun" href="subpages/tab-webview-subpage-service.html">
				<span class="mui-icon iconfont icon-jk"></span>
				<span class="mui-tab-label">资讯</span>
			</a>
			<a class="mui-tab-item dingdan" href="subpages/tab-webview-subpage-order.html">
				<span class="mui-icon iconfont icon-dd"></span>
				<span class="mui-tab-label">订单</span>
			</a>
			<a class="mui-tab-item xinxi" href="subpages/tab-webview-subpage-talk.html">
				<span class="mui-icon iconfont icon-ly"><span class="mui-badge" id="red_dian"></span></span>
				<span class="mui-tab-label">信息</span>
			</a>

			<a class="mui-tab-item wode" href="subpages/tab-webview-subpage-my.html">
				<span class="mui-icon iconfont icon-wd"></span>
				<span class="mui-tab-label">我的</span>
			</a>

			<!--<div class="mui-popup mui-popup-in" style="display: block;">
				<div class="mui-popup-inner">
					<div class="mui-popup-title">'+tishi+'</div>
					<div class="mui-popup-text">'+content1+'</div>
					<div class="mui-popup-text">
						'+content2+'
					</div>
				</div>
				<div class="mui-popup-buttons"><span class="mui-popup-button" id="quxiao">取消</span><span class="mui-popup-button mui-popup-button-bold" id="queding">确认</span></div>
			</div>-->
		</nav>

		<script src="js/mui.min.js"></script>
		<script type="text/javascript" src="js/app.js"></script>
		<script type="text/javascript" src="js/xiangyingshi.js"></script>
		<script type="text/javascript" src="js/jquery-3.1.1.js"></script>
		<script type="text/javascript" src="js/constants.js"></script>
		<script type="text/javascript" src="js/qs/qs.update.js"></script>
		<script type="text/javascript" src="js/sdk/lib/md5/spark-md5.js"></script>
		<script type="text/javascript" src="js/sdk/lib/md5/md5.min.js"></script>
		<script type="text/javascript" src="js/sdk/lib/base64/base64.js"></script>
		<script type="text/javascript" src="js/sdk/webim.js"></script>
		<!--描述：展示获取的一条消息-->
		<!--描述：设置聊天对象-->
		<script type="text/javascript" src="js/sdk/webim.js"></script>
		<script type="text/javascript" src="js/sdk/webim/index_receive_new_msg.js"></script>
		<script type="text/javascript" src="js/sdk/webim/login.js"></script>
		<script>
			//			localStorage.clear();
			//			plus.storage.clear();
			localStorage.removeItem("upitem");
			var subpages = ['subpages/tab-webview-subpage-home.html',
				'subpages/tab-webview-subpage-service.html',
				'subpages/tab-webview-subpage-order.html',
				'subpages/tab-webview-subpage-talk.html',
				'subpages/tab-webview-subpage-my.html'
			];
			//当前激活选项
			var activeTab = subpages[0];
			var title = document.getElementById("title");
			var targetTab;

			function preload() {

				var menu_style = {
					left: "-70%",
					width: '70%',
					popGesture: "none",
					render: "always"
				};

				if(mui.os.ios) {
					menu_style.zindex = -1;
				}

			}

			mui.plusReady(function() {

				//读取本地存储，检查是否为首次启动
				var showGuide = plus.storage.getItem("lauchFlag");
				//				//仅支持竖屏显示
				plus.screen.lockOrientation("portrait-primary");
				//				if(showGuide) {
				//					//有值，说明已经显示过了，无需显示；
				//					//关闭splash页面；
				//					plus.navigator.closeSplashscreen();
				//					plus.navigator.setFullscreen(false);
				//					//预加载
				//					preload();
				//				} else {
				//显示启动导航
				mui.openWindow({
					id: 'guide',
					url: 'guide.html',
					styles: {
						popGesture: "none"
					},
					show: {
						aniShow: 'none'
					},
					waiting: {
						autoShow: false
					}
				});
				//延迟的原因：优先打开启动导航页面，避免资源争夺
				setTimeout(function() {
					//预加载
					preload();
				}, 200);
				//}

				document.addEventListener("netchange", wainshow, false);

				function wainshow() {
					if(plus.networkinfo.getCurrentType() == plus.networkinfo.CONNECTION_NONE) {
						mui.toast("确认手机是否连接网络！");
					}
				}

				var chatId;
				document.addEventListener("pause", onAppPause, false);

				function onAppPause() {
					localStorage.setItem("pause", "true");
					console.log("pause");
				}
				document.addEventListener("resume", onAppReume, false);

				function onAppReume() {
					localStorage.setItem("pause", "false");
					console.log("resume");
				}

				plus.navigator.setStatusBarStyle('light');
				plus.runtime.setBadgeNumber(0);

				// 获取本地应用资源版本号
				plus.runtime.getProperty(plus.runtime.appid, function(inf) {
					console.log("版本号:" + inf.version);
					wgtVer = inf.version;
					checkUpdateForIndex(wgtVer, function() {
						//commonHttpUtils(serverAddress + showdetailUrl, "get", {}, sussess, error);
					});
				});
				//plus.push.setAutoNotification(true);
				//				plus.push.addEventListener("click", function(msg) {
				//					if(msg.content == "新消息") { //判断是聊天消息
				//						mui.openWindow({
				//							url: './familydoctor/message_list.html',
				//							id: 'familydoctormessage_list.html',
				//							show: {
				//								autoShow: false, //页面loaded事件发生后自动显示，默认为true
				//								event: 'loaded' //页面显示时机，默认为titleUpdate事件时显示
				//							},
				//							waiting: {
				//								autoShow: true //自动显示等待框，默认为true
				//							},
				//							extras: {
				//
				//							}
				//						});
				//					} else {
				//						var data1 = JSON.parse(msg.content);
				//						//tc="000000"是抢单  "111111"是退单
				//						if(data1.tc == "000000") {
				//							//alert("系统根据您的情况，为您匹配" + data1.name + "护士，10分钟之内，医护人员会主动联系您");
				//							mui.openWindow({
				//								id: 'c02_order_xiangqing.html',
				//								url: 'order/c02_order_xiangqing.html',
				//								show: {
				//									autoShow: false, //页面loaded事件发生后自动显示，默认为true
				//									event: 'loaded' //页面显示时机，默认为titleUpdate事件时显示
				//								},
				//								waiting: {
				//									autoShow: true //自动显示等待框，默认为true
				//								},
				//								extras: {
				//									orderid: data1.orderid //扩展参数
				//								}
				//							});
				//						} else if(data1.tc == "000003") {
				//							var template = plus.webview.getWebviewById("subpages/tab-webview-subpage-talk.html");
				//							template.reload();
				//						}
				//					}
				//
				//				});
				plus.push.addEventListener("click", function(msg) {
					if(msg.content == "新消息") { //判断是聊天消息
						mui.openWindow({
							url: './familydoctor/message_list.html',
							id: 'familydoctormessage_list.html',
							show: {
								autoShow: false, //页面loaded事件发生后自动显示，默认为true
								event: 'loaded' //页面显示时机，默认为titleUpdate事件时显示
							},
							waiting: {
								autoShow: true //自动显示等待框，默认为true
							},
							extras: {

							}
						});
					}
				});
				// 接收推送消息
				plus.push.addEventListener("receive", function(msg) {
					if(msg.aps) {
						//alert('接收到在线APNS消息');
					} else {
						//alert('接收到在线透传消息');
					}
					if(msg.content == "新消息") { //判断是聊天消息
						console.log("新消息return ");
						return;
					}
					if(msg.content) {
						var data1 = JSON.parse(msg.content);
						//alert("You clicked:" + JSON.parse(msg.content));
						//alert("测试推单消息1" + msg.content);
						//alert("测试推单消息2" + JSON.stringify(msg.content));
						//tc="000000"是抢单  "111111"是退单,servicetype=0,正常单子，servicetyp=1,报告解读
						if(data1.tc == "000000") {
							//alert("系统根据您的情况，为您匹配" + data1.name + "护士，10分钟之内，医护人员会主动联系您");
							if(data1.servicetype == "0") {
								mui.openWindow({
									id: 'c02_order_xiangqing.html',
									url: 'order/c02_order_xiangqing.html',
									show: {
										autoShow: false, //页面loaded事件发生后自动显示，默认为true
										event: 'loaded' //页面显示时机，默认为titleUpdate事件时显示
									},
									waiting: {
										autoShow: true //自动显示等待框，默认为true
									},
									extras: {
										orderid: data1.orderid //扩展参数
									}
								});
							} else if(data1.servicetype == "1") {
								mui.openWindow({
									id: 'online_answer_order_xiangqing.html',
									url: 'online_answer_order/online_answer_order_xiangqing.html',
									show: {
										autoShow: false, //页面loaded事件发生后自动显示，默认为true
										event: 'loaded' //页面显示时机，默认为titleUpdate事件时显示
									},
									waiting: {
										autoShow: true //自动显示等待框，默认为true
									},
									extras: {
										orderid: data1.orderid //扩展参数
									}
								});
							}

						} else if(data1.tc == "000003") {
							var template = plus.webview.getWebviewById("subpages/tab-webview-subpage-talk.html");
							template.reload();
						}

					} else {
						var data1 = JSON.parse(msg.payload);
						//alert("You clicked:" + JSON.parse(msg.content));
						//alert("测试推单消息1" + msg.content);
						//alert("测试推单消息2" + JSON.stringify(msg.content));
						//tc="000000"是抢单  "111111"是退单
						if(data1.tc == "000000") {
							if(data1.servicetype == "0") {

								mui.openWindow({
									id: 'c02_order_xiangqing.html',
									url: 'order/c02_order_xiangqing.html',
									show: {
										autoShow: false, //页面loaded事件发生后自动显示，默认为true
										event: 'loaded' //页面显示时机，默认为titleUpdate事件时显示
									},
									waiting: {
										autoShow: true //自动显示等待框，默认为true
									},
									extras: {
										orderid: data1.orderid //扩展参数
									}
								});
							} else if(data1.servicetype == "1") {
								mui.openWindow({
									id: 'online_answer_order_xiangqing.html',
									url: 'online_answer_order/online_answer_order_xiangqing.html',
									show: {
										autoShow: false, //页面loaded事件发生后自动显示，默认为true
										event: 'loaded' //页面显示时机，默认为titleUpdate事件时显示
									},
									waiting: {
										autoShow: true //自动显示等待框，默认为true
									},
									extras: {
										orderid: data1.orderid //扩展参数
									}
								});
							}
						} else if(data1.tc == "000003") {
							var template = plus.webview.getWebviewById("subpages/tab-webview-subpage-talk.html");
							template.reload();
						}
					}
				});

				var topoffset = '45px';
				if(plus.navigator.isImmersedStatusbar()) { // 兼容immersed状态栏模式
					// 获取状态栏高度并根据业务需求处理，这里重新计算了子窗口的偏移位置
					topoffset = (Math.round(plus.navigator.getStatusbarHeight()) + 45) + 'px';
					document.querySelector("header").style.height = topoffset;
					document.querySelector("header").style.paddingTop = "20px";
				}
				var subpage_style = {
					top: topoffset,
					bottom: '51px'
				};

				var aniShow = {};
				var settings = app.getSettings();
				if(localStorage.getItem("num") == "1") {
					mui.toast("您没有实名认证！");
					mui.openWindow({
						url: "geren_message/d02_geren_message.html",
						id: "d02_geren_message.html"
					});
					localStorage.removeItem("num");
					return false;
				}
				var self = plus.webview.currentWebview();
				for(var i = 0; i < 5; i++) {
					var temp = {};
					var sub = plus.webview.create(subpages[i], subpages[i], subpage_style);
					if(i > 0) {
						sub.hide();
					} else {
						temp[subpages[i]] = "true";
						mui.extend(aniShow, temp);
					}
					self.append(sub);
				}

				mui.oldBack = mui.back;
				var backButtonPress = 0;
				mui.back = function(event) {
					backButtonPress++;
					if(backButtonPress > 1) {
						plus.runtime.quit();
					} else {
						plus.storage.removeItem("roster");
						plus.nativeUI.toast('再按一次退出应用');
					}
					setTimeout(function() {
						backButtonPress = 0;
					}, 1000);
					return false;
				};

				//选项卡点击事件
				mui('.mui-bar-tab').on('tap', 'a', function(e) {

					targetTab = this.getAttribute('href');

					if(targetTab == "subpages/tab-webview-subpage-home.html") {
						plus.webview.getWebviewById(targetTab).reload(true);
					}
					if(targetTab == "subpages/tab-webview-subpage-service.html") {
						plus.webview.getWebviewById(targetTab).reload(true);
					}
					if(targetTab == "subpages/tab-webview-subpage-talk.html") {
						if(localStorage.getItem("TOKENID") == null) {
							mui.openWindow({
								url: "login/login.html",
								id: 'login.html'
							});
							return false;
						}

						plus.webview.getWebviewById(targetTab).reload(true);
						//$("#red_dian").hide();
					}
					if(targetTab == "subpages/tab-webview-subpage-order.html") {
						if(localStorage.getItem("TOKENID") == null) {
							mui.openWindow({
								url: "login/login.html",
								id: 'login.html'

							});
							return false;
						}
						plus.webview.getWebviewById(targetTab).reload(true);
					}
					if(targetTab == "subpages/tab-webview-subpage-my.html") {
						if(localStorage.getItem("TOKENID") == null) {
							mui.openWindow({
								url: "login/login.html",
								id: 'login.html'

							});
							return false;
						}
						plus.webview.getWebviewById(targetTab).reload(true);
					}

					if(targetTab == activeTab) {
						return;
					}
					var tabSpan = this.querySelector('.mui-tab-label');
					//更换标题
					title.innerHTML = tabSpan.title ? tabSpan.title : tabSpan.innerHTML;
					//显示目标选项卡
					//若为iOS平台或非首次显示，则直接显示
					if(mui.os.ios || aniShow[targetTab]) {
						plus.webview.show(targetTab);
						plus.nativeUI.closeWaiting();
					} else {
						//否则，使用fade-in动画，且保存变量
						var temp = {};
						temp[targetTab] = "true";
						mui.extend(aniShow, temp);
						plus.webview.show(targetTab, "fade-in", 300);
						plus.nativeUI.closeWaiting();
					}
					//隐藏当前;
					plus.webview.hide(activeTab);
					//更改当前活跃的选项卡
					activeTab = targetTab;
				});

			});
			//开始登录sdk并监听
			var startListeners = function() {
				webim.login(webimLoginInfo, listeners, {},
					function(resp) {},
					function(err) {}
				);
			}
			//结束登录sdk并取消监听
			var endListeners = function() {
				webim.logout();
			}
			this.startListeners();

			var setItemActive = function(itemdown, itemup) {
				//更换标题
				title.innerHTML = "订单";
				var status = itemdown;
				var upstatus = itemup;
				localStorage.setItem("upitem", upstatus);
				mui.fire(plus.webview.getWebviewById('subpages/tab-webview-subpage-order.html'), 'orderend', {
					UPSTATUS: upstatus
				});
				targetTab = subpages[status];
				if(targetTab != activeTab) {
					if(status == 2) {
						document.querySelector(".dingdan").setAttribute("class", "mui-tab-item dingdan mui-active");
						document.querySelector(".home").setAttribute("class", "mui-tab-item home");
						document.querySelector(".xinxi").setAttribute("class", "mui-tab-item xinxi");
						document.querySelector(".wode").setAttribute("class", "mui-tab-item wode");
					}
					plus.webview.show(targetTab);
					plus.webview.hide(activeTab);
					//plus.webview.getWebviewById(targetTab).reload(true);
					//更改当前活跃的选项卡
					activeTab = targetTab;
				}
				plus.webview.getWebviewById("subpages/tab-webview-subpage-order.html").reload(true);
			};

			var setItemActiveMain = function() {

				var defaultTab = document.getElementById("defaultTab");
				//模拟首页点击
				var current = document.querySelector(".mui-bar-tab>.mui-tab-item.mui-active");
				if(defaultTab !== current) {
					current.classList.remove('mui-active');
					defaultTab.classList.add('mui-active');
				}
				activeTab = current;
				targetTab = subpages[0];
				mui.trigger(defaultTab, 'tap');
			};

			var changeReddian = function() {
				$("#red_dian").show();
			}
			var changeReddian_X = function() {
				$("#red_dian").hide();
			}
			// 城市选择
			//			var showCityPickerButton = document.getElementById('chooseCity');
			//			showCityPickerButton.addEventListener('tap', function(event) {
			//				if(window.plus) {
			//					mui.openWindow({
			//						url: 'main_sub/indexed-list.html',
			//						id: 'indexed-list.html',
			//						waiting: {
			//							autoShow: false //自动显示等待框，默认为true
			//						},
			//						styles: {
			//							//top: topoffset,
			//							bottom: '0px',
			//							background: 'transparent',
			//							opacity: 1,
			//							zindex: "100"
			//						}
			//					});
			//
			//				} else {
			//					mui.toast("请在html5+引擎环境使用");
			//				}
			//			}, false);

			
		</script>
	</body>

</html>